package com.ttc.group2.videochat.controller;

import com.quickblox.core.exception.QBResponseException;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
import com.ttc.group2.videochat.R;
import com.ttc.group2.videochat.model.DataHolder;

import android.content.Context;
import android.support.v7.internal.view.menu.MenuBuilder;
import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

public class OverflowPeopleSelectedListener implements OnClickListener {
	private Context mContext;
	private QBUser qbUser;

	public OverflowPeopleSelectedListener(Context context, QBUser qbUser) {
		this.mContext = context;
		this.qbUser = qbUser;
	}

	@Override
	public void onClick(View v) {
		PopupMenu popupMenu = new PopupMenu(mContext, v) {

			@Override
			public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
				switch (item.getItemId()) {
				case R.id.overflow_remove:
					// remove people
					removeUser();
					return true;
				case R.id.overflow_view_profile:
					// view profile
					DataHolder.getDataHolder().getQBUser(qbUser.getId());
					// put data
					// show view profile activity
					return true;

				default:
					return super.onMenuItemSelected(menu, item);
				}

			}

		};

		popupMenu.inflate(R.menu.overflow_menu_item);
		// add or remove item by code here
		popupMenu.show();
	}
	
	private void removeUser() {
		try {
			QBUsers.deleteUser(qbUser.getId());
		} catch (QBResponseException e) {
			e.printStackTrace();
		}
	}
	
}
